<?php
/**
 * Created by PhpStorm.
 * User: wangkk
 * Date: 2019-04-24 10:04
 * Description: {选择适用商品}
 */
    $this->context->layout = false; //不使用布局
?>
<html>
<head>
    <meta charset="utf-8">
    <title>选择适用商品</title>
    <script src="https://cdn.bootcss.com/jquery/3.4.0/jquery.js"></script>
    <script src="https://cdn.bootcss.com/twitter-bootstrap/4.3.0/js/bootstrap.min.js"></script>
    <link href="https://cdn.bootcss.com/twitter-bootstrap/4.3.0/css/bootstrap.min.css" rel="stylesheet">
    <script src="/plugin/layer/layer.js"></script>
</head>
<bod>
    <table class="table table-striped table-bordered" style="padding-bottom: 50px;">
        <tbody id="goods-body">

        </tbody>
    </table>
</bod>
</html>
<script>
    $(function(){
        //获取适用商品
        $.get(
            '/coupon/ajaxgetapplygoods',
            function(json){
                if(json.code != 0){
                    var span_html_str = '<span>'+json.msg+'</span>';
                    $('#goods-body').append(span_html_str);
                }else{
                    var goods = json.data;
                    var goods_html_str = '';
                    for(i in goods){
                        goods_html_str += '<tr>' +
                            '<td>'+'<input type="checkbox" value="'+goods[i].id+'"></td>' +
                            '<td>'+goods[i].name+'</td>' +
                            '</br>';
                    }
                    $('#goods-body').append(goods_html_str);
                    $('table').after('<button id="submit-button" onclick="closegoodsiframe()" class="btn btn-primary">确定</button>');
                }
            },'json'
        );
    });
    //iframe索引
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    //关闭iframe
    function closegoodsiframe(){
        //获取到选择的数据
        var checked_value = [];
        $('input[type="checkbox"]:checked').each(function () {
            checked_value.push($(this).val());
        });
        window.parent.setApplygoods(checked_value);
        parent.layer.close(index);
    }
</script>
